home *** CD-ROM | disk | FTP | other *** search
- Path: news.dal.ca!news
- From: keichele@ac.dal.ca (Klaus Eichele)
- Newsgroups: comp.lang.c
- Subject: Re: Help!
- Date: Sun, 10 Mar 1996 06:02:43 GMT
- Organization: Dalhousie University
- Message-ID: <4htd86$r01@News.Dal.Ca>
- References: <31420B3D.75A0@utoronto.ca>
- NNTP-Posting-Host: rewasylishen.chem.dal.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- Dave Goldstein <dave.goldstein@utoronto.ca> wrote:
-
- >I'm working on a program that reads in string after string of input and
- >parses each string looking for valid integer numbers. I need to retain
- >all these #'s to do some calculations when when it hits eof, but my
- >problem is that there is *no* maximum amount of numbers. Therefore I
- >can't just say:
- >#MAX_NUM 100
- >int values[MAX_NUM]
-
- >which is what I'm used to doing. So I need to use dynamic memory
- >allocation, but how do I allocate a certain amount of memory if I don't
- >even have any idea of how many integers there are going to be in the
- >input??? Sounds like vertigo to me. I can't use a command line
- >argument, nor can I just allocate a huge amount of space for the
- >program.
-
- >From what I also understand, once something is malloc'ed, it becomes
- >fixed in size. Sorry if I'm rambling, but if you have an idea please
- >write me by mail at:
-
- >dave.goldstein@utoronto.ca
-
- >Thanks in advance!
-
- Hi, this is what the documentation for my compiler says about realloc:
-
- ------------------------------------------------------
- #include <stdlib.h>
- void *realloc(void *block, size_t size);
-
- Description
- Reallocates main memory.
- realloc attempts to shrink or expand the previously allocated block to
- size bytes. If size is zero, the memory block is freed and NULL is
- returned. The block argument points to a memory block previously
- obtained by calling malloc, calloc, or realloc. If block is a NULL
- pointer, realloc works just like malloc. realloc adjusts the size of
- the allocated block to size, copying the contents to a new location if
- necessary.
-
- --------------------------------------
-
- Good Luck,
- Klaus
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Klaus Eichele keichele@is.dal.ca
- http://is.dal.ca/~keichele/keichele.html
-
-